package com.hxht.cmp.utils;

import com.hxht.cmp.common.Constants;
import com.hxht.cmp.entity.Court;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 加工CourtId
 */
public class CourtUidListUtils{
    /**
     * 获取传入法院Uid的所有下级法院Uid
     *
     * @param courtUid
     * @return
     */
    public static List<String> getCourtUidList(String courtUid) {
        Court nowCourt = Constants.COURT_MAP.get(courtUid);
        List<String> courtCodes = new ArrayList<>();
        //传入courtUid与当前项目中的courtUid不一致获取其下级法院courtUid
        if (!Objects.equals(courtUid, Constants.CENTRAL_COURT.getUid())) {
            for (Court court : Constants.COURT_LIST) {
                if (Objects.equals(courtUid, court.getUid()) || Objects.equals(nowCourt.getUid(), court.getParentUid())) {
                    courtCodes.add(court.getUid());
                }
            }
        }
        return courtCodes;
    }

    /**
     * 获取传入Uid的所有下级法院Uid
     * @param courtUid
     * @return
     */
    public static List<String> getAllCourUidList(String courtUid){
        List<String> courtUids = new ArrayList<>();
        courtUids.add(courtUid);
        for (Court court : Constants.COURT_LIST) {
            if (Objects.equals(courtUid, court.getParentUid())) {
                courtUids.add(court.getUid());
                for (Court court1 : Constants.COURT_LIST) {
                        if (Objects.equals(court.getUid(),court1.getParentUid())){
                            courtUids.add(court1.getUid());
                        }
                }
            }
        }
        return courtUids;
    }
    public static List<String> getChildrenCourtUidList(String courtUid) {
        List<String> courtUids = new ArrayList<>();
        for (Court court : Constants.COURT_LIST) {
            if (Objects.equals(courtUid, court.getParentUid())) {
                courtUids.add(court.getUid());
            }
        }
        return courtUids;
    }

}
